#include <iostream>
#include <string>
using namespace std;

//类对象作为类成员

//手机类
class Phone
{
public:
    string name; // 品牌名

    Phone(string name):name(name)
    {
        cout << "Phone 构造函数调用" << endl;
    }

    ~Phone()
    {
        cout << "Phone 析构函数调用" << endl;
    }
};

//人类
class Person
{
public:
    //姓名
    string name;
    //手机
    Phone phone;

    Person(string Name, string pName):name(Name),phone(pName) // Phone phone = pName(隐式转换法)
    {
        cout << "Person 构造函数调用" << endl;
    }

    ~Person()
    {
        cout << "Person 析构函数调用" << endl;
    }
};

void test1()
{
    Person p("张三", "华为");
    //构造时候，先构造对象成员，再构造自身
    //析构时候，先析构自身，再析构对象成员
    
    cout << p.name << "拿着" << p.phone.name << endl;
}

int main()
{
    test1();
    return 0;
}